﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using Sale_Operation;
using Sale_Common;
using SaleSystem;
using Sale_Model;
using ExtAspNet;

namespace SaleSystem.ComPage
{
    public partial class frm_ProductChooseList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                bn_Close.OnClientClick = ExtAspNet.ActiveWindow.GetHideReference();
                GetAndBind();
            }
        }
        protected void gv_List_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            gv_List.PageIndex = e.NewPageIndex;
            GetAndBind();
        }
        protected void bn_SearchClick(object sender, EventArgs e)
        {
            GetAndBind();
        }
        private void GetAndBind()
        {
            FormatGrid(gv_List);
            InitCondition();
            dtList = Manager.GetList(strCondition, gv_List.PageIndex + 1, ref iRecordCount);
            gv_List.DataSource = dtList;
            gv_List.DataBind();
            gv_List.RecordCount = iRecordCount;
        }
        /// <summary>
        /// 获取查询条件
        /// </summary>
        public override void InitCondition()
        {
            if (tb_PInfo_CH.Text.Trim() != "")
            {
                strCondition += " PInfo_CH LIKE '%" + ValueHandler.GetStringValue(tb_PInfo_CH.Text, ValueHandler.CharHandlerType.IsRepChar) + "%' AND ";
            }
            if (tb_PInfo_Code.Text.Trim() != "")
            {
                strCondition += " PInfo_Code LIKE '%" + ValueHandler.GetStringValue(tb_PInfo_Code.Text, ValueHandler.CharHandlerType.IsRepChar) + "%' AND ";
            }
            if (tb_PInfo_Name.Text.Trim() != "")
            {
                strCondition += " PInfo_Name LIKE '%" + ValueHandler.GetStringValue(tb_PInfo_Name.Text, ValueHandler.CharHandlerType.IsRepChar) + "%' AND ";
            }
            if (tb_PInfo_Number.Text.Trim() != "")
            {
                strCondition += " PInfo_Number LIKE '%" + ValueHandler.GetStringValue(tb_PInfo_Number.Text, ValueHandler.CharHandlerType.IsRepChar) + "%' AND ";
            }
            if (tb_PInfo_Pwd.Text.Trim() != "")
            {
                strCondition += " PInfo_Pwd LIKE '%" + ValueHandler.GetStringValue(tb_PInfo_Pwd.Text, ValueHandler.CharHandlerType.IsRepChar) + "%' AND ";
            }
            
            if (!string.IsNullOrEmpty(strCondition))
                strCondition = strCondition.Substring(0, strCondition.Length - 4);

        } 
        protected void gv_List_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "ok")
            {
                //TreeNodeCollection nodes 
                string strText = ValueHandler.GetStringValue( gv_List.DataKeys[e.RowIndex][1] );
                string strValue = ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][0]);
                string strBBDeta_Count = "1";
                string strBBDeta_CostPrice = ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][2]);
                string strPInfo_Price = ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][3]);
                string strTotal = (ValueHandler.GetDecNumberValue(strBBDeta_CostPrice) * ValueHandler.GetIntNumberValue(strBBDeta_Count)).ToString();
                PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(strText, strValue, strBBDeta_Count, strBBDeta_CostPrice,strTotal, strPInfo_Price) + ActiveWindow.GetHidePostBackReference());
                
            }
        }
        #region Property
 
        ProductInfoOp Manager = new ProductInfoOp();
        #endregion

       
    }
}
